<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Monolog\Logger;
use Yansongda\Pay\Pay;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
        $this->app->singleton('alipay',function (){
           $config = config('pay.alipay');
            $config['notify_url'] = 'http://requestbin.fullcontact.com/107d18q1';
            $config['return_url'] = route('payment.alipay.return');
           //判断运行环境
            if(app()->environment() !== 'production'){
                $config['mode'] = 'dev';
                $config['log']['level'] = Logger::DEBUG;
            }else{
                $config['log']['level'] = Logger::WARNING;
            }
            //创建支付宝对象
            return Pay::alipay($config);
        });

        $this->app->singleton('wechat_pay',function (){
            $config = config('pay.wechat');
            //判断运行环境  微信支付没有开发模式
            if(app()->environment() !== 'production'){
                $config['log']['level'] = Logger::DEBUG;
            }else{
                $config['log']['level'] = Logger::WARNING;
            }
            //创建支付宝对象
            return Pay::wechat($config);
        });
    }
}
